package engine.logic
{
	import engine.data.ModelLocator;
	import engine.net.event.CustomMsgEvent;
	import engine.net.messages.CustomToClientFlag;
	import engine.net.messages.CustomToServerFlag;
	import engine.net.mgr.SystemSender;
	import engine.newUi.SitAlerLogic;
	import engine.newUi.SitAlerUI;
	import engine.ui.AlertUI;
	
	import flash.utils.getQualifiedClassName;
	
	import newx.com.config.StaticIni;

	/**
	 *请求付费消息 
	 * @author yanghr
	 * 
	 */	
	public class RequestForCost
	{
		private static var _self:RequestForCost;
		private var _model:ModelLocator;
		private const alertObj:Object={4:"Kungfu_UIString7",10:"Kungfu_UIString13"};
		private var _id:int;
		private var _call:Function;
		private var _plist:Array;
		
		private var _isListening:Boolean=false;
		public static function getInstance():RequestForCost
		{
			if(_self==null)
			{
				_self=new RequestForCost();
			}
			return _self;
		}
		public function RequestForCost()
		{
			_model=ModelLocator.getInstance();
			// 返回付费消耗
			_model.addEventListener(String(CustomToClientFlag.	SERVER_CUSTOMMSG_REQUEST_CHARGE) ,costInfo);
		}
		public function request(id:int,callBack:Function,...args):void
		{
			_id=id;
			_call=callBack;
			_plist=args;
			var arr:Array=[];
			arr=arr.concat(id,args);
			_isListening=true;
			SystemSender.getInstance().CustomMsgEx(CustomToServerFlag.CLIENT_CUSTOMMSG_REQUEST_CHARGE,arr)
		}
		private function costInfo(e:CustomMsgEvent):void
		{
			if(!_isListening||!alertObj.hasOwnProperty(e.pList[0]))return ;
			_isListening=false
//			trace("RequestForCost.costInfo(e)",e.pList);
//			AlertUI.showAlert(" ",StaticIni.getSwfLangStrVar(alertObj[_id],[e.pList[1]]),AlertUI.OK|AlertUI.CANCEL,alertCallBack);
//			SitAlerLogic.getIntatic().Func(sitCallback);
//			SitAlerLogic.getIntatic().setInfo(alertObj[_id],[e.pList[1]]);
			SitAlerLogic.getIntatic().setUIinfo(alertObj[_id],[e.pList[1]],sitCallback,getQualifiedClassName(this)+_id/*e.pList[0]*/);
//			if(!SitAlerUI.getInstance().created)
//				SitAlerUI.getInstance().showOrHide();
		}
		private function sitCallback():void
		{
			_call.apply(this,_plist);
		}
		/**
		 * 添加黑名单回调 
		 * @param type
		 * @param str
		 * @param clickData   点击的
		 * 
		 */			
		private function alertCallBack(type:int, str:String, clickData:*):void
		{
			if(AlertUI.OK == type || AlertUI.YES == type)
			{
				_call.apply(this,_plist);
			}
			
		}
	}
}